Add continuously growing collection Generators#849
Open
mdedetrich wants to merge 1 commit into
Open
Conversation
776f0f4 to
3cb4ff2
Compare
3cb4ff2 to
1b9c0da
Compare
Author
|
@armanbilge Would it be possible to look into this? |
Contributor
|
@mdedetrich but is it really necessary to extend def buildableOfCondGen[C, T](fillCondition: C => Boolean, g: Gen[T])(
implicit
evb: Buildable[T, C],
evt: C => Iterable[T]
): Gen[C] =
Gen.infiniteLazyList(g).map { ll =>
val it = ll.iterator
val bldr = evb.builder
while (!fillCondition(bldr.result()))
bldr += it.next()
bldr.result() // sub-optimal: is called twice for the same result, can be improved!
}
val vgen: Gen[Vector[Int]] = buildableOfCondGen[Vector[Int], Int](_.size == 123, Gen.chooseNum(456, 789))
Prop.forAll(vgen) { v =>
v.size == 123
}.check()And perhaps you even don't have to worry about |
Author
|
Perfect thanks, I didn't realize there was a flexible |
Contributor
|
Hi @mdedetrich , sorry for the long ping. Just to clarify with you: would you like to continue on this PR or do you think it can be closed? Thank you for your effort in any case! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds generators which allow you to generate a collection/list that continuously grows until a condition/predicate is fullfilled (with the input of the condition being the current state of the collection being generated).
I am creating this PR because I currently have a usecase where I need to create a collection that is of specific size (in bytes, not number of elements) due to testing multipart uploads and having to make sure that generated test data is of least a specific chunk size but I suppose the problem is generic enough that it can apply to other issues.
Due to
Genbeing asealed traitand certain methods insideGenbeing private its not that easy to extendGenwith your own generator methods.The naming of the methods can probably be done better, also not sure if I need to add tests for these and if so what I should be testing for/what they should look like. The
failureHint's approach is also an open question due to the fact that its obviously not possible to figure out the size of the resulting collection.